#include "../../common/message.hpp"
#include "../../common/net.hpp"
#include <thread>

void onMessage(const rpc::BaseConnection::ptr& conn,rpc::BaseMessage::ptr & msg)
{
    std::string body = msg->serialize();
    std::cout<<body<<std::endl;

}

int main()
{
    rpc::BaseClient::ptr client = rpc::ClientFactory::create("127.0.0.1",9090);
    client->setMessageCallback(onMessage);
    client->connect();
    rpc::RpcRequest::ptr rpc_req = rpc::MessageFactory::create<rpc::RpcRequest>();
    rpc_req->setId(rpc::UUID::uuid());
    rpc_req->setMType(rpc::MType::REQ_RPC);
    rpc_req->setMethod("Add");
    Json::Value param;
    param["num1"] =11;
    param["num2"] =22;
    rpc_req->setParams(param);
    client->send(rpc_req);
    client->shutdown();
    std::this_thread::sleep_for(std::chrono::seconds(20));
    return 0;
}
